package edu.ccut.saturn.studio.database.model;

import java.util.List;

import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.IActionFilter;


import edu.ccut.saturn.studio.Activator;
import edu.ccut.saturn.studio.Images;

/**
 * 数据库表
 * 
 * @author 谷钰
 * @version 1.0 2008.12.02
 */
public class SqlTable extends SaturnTree implements IActionFilter {
	private SqlSchema schema = null;

	public SqlTable(String name, SqlSchema schema) {
		super(name);

		this.schema = schema;
	}

	@Override
	public void expand() throws Exception {
		if (super.hasChildren()) {
			this.removeChildren();
		}

		List<SqlColumn> columns = this.schema.getTableColumns(super.getName());

		if (columns != null) {
			for (SqlColumn typeSize : columns) {
				super.addChild(typeSize);
			}
		}
		
		super.setOpen(true);
	}

	@Override
	public Image getImage() {
		return Activator.getImage(Images.DATABASE_TABLE);
	}

	public boolean testAttribute(Object target, String name, String value) {
		return false;
	}

	public String getDescription() {
		StringBuffer stringbuffer = new StringBuffer();
		stringbuffer.append("<b>").append("Schema:").append("<b>").append(
				this.schema.getName());

		return stringbuffer.toString();
	}
}
